//-- GUI COMBO: { !function(global) { 'use strict'; function GUICombo(elem, settings) { this.$element = jQuery(elem); this.__SETTINGS = jQuery.extend({ inputSelector: '.' + GUICombo.JS_CLASS_SELECT, overflowOffset: 0, classPlaceholder: GUICombo.JS_CLASS__PLACEHOLDER, classOverflow: GUICombo.JS_CLASS__OVERFLOW, classDisabled: GUICombo.JS_CLASS__DISABLED }, this.$element.data(GUICombo.DATA) || {}, settings || {}); this.__construct(); } //-- CONST: { Object.defineProperties(GUICombo, { 'NAMESPACE_DATA': { value: (global.NAMESPACE_DATA ? (global.NAMESPACE_DATA + '-') : '') + 'gui-combo' }, 'NAMESPACE_JS_CLASS': { value: (global.NAMESPACE_JS_CLASS ? (global.NAMESPACE_JS_CLASS + '-') : '') + 'GUI-Combo' }, 'NAMESPACE_EVENT': { value: (global.NAMESPACE_EVENT ? (global.NAMESPACE_EVENT + ':') : '') + 'gui:combo' } }); Object.defineProperties(GUICombo, { 'DATA': { value: GUICombo.NAMESPACE_DATA }, 'JS_CLASS': { value: 'JS-' + GUICombo.NAMESPACE_JS_CLASS }, 'EVENT_PREFIX': { value: 'js:' + GUICombo.NAMESPACE_EVENT } }); Object.defineProperties(GUICombo, { 'JS_CLASS__PLACEHOLDER': { value: GUICombo.JS_CLASS + '-placeholder' }, 'JS_CLASS__OVERFLOW': { value: GUICombo.JS_CLASS + '-overflow' }, 'JS_CLASS__DISABLED': { value: GUICombo.JS_CLASS + '-disabled' }, 'JS_CLASS_SELECT': { value: GUICombo.JS_CLASS + '-Select' }, 'JS_CLASS_VIEW': { value: GUICombo.JS_CLASS + '-View' }, 'JS_CLASS_VALUE': { value: GUICombo.JS_CLASS + '-Value' }, 'EVENT_INIT': { value: GUICombo.EVENT_PREFIX + ':init' }, 'EVENT_READY': { value: GUICombo.EVENT_PREFIX + ':ready' } }); Object.defineProperties(GUICombo, { 'UPDATE_EVENTS': { value: [ 'change', 'keydown', 'keyup', 'keypress', 'js:update', ''].join('.' + GUICombo.JS_CLASS + ' ') } }); //-- } /const. GUICombo.prototype.__construct = function __construct() { this.$select = this.$element.find(this.__SETTINGS.inputSelector); this.$view = this.$element.find('.' + GUICombo.JS_CLASS_VIEW); this.$value = this.$element.find('.' + GUICombo.JS_CLASS_VALUE); this.__init(); }; GUICombo.prototype.__init = function __init() { this.$element.trigger(GUICombo.EVENT_INIT, { instance: this }); this.$select .on(GUICombo.UPDATE_EVENTS, this.update.bind(this)) .trigger('js:update'); this.__ready(); }; GUICombo.prototype.__ready = function __ready() { this.$element .removeAttr('data-' + GUICombo.DATA) .data(GUICombo.DATA, { instance: this, __SETTINGS: this.$element.data(GUICombo.DATA) || {} }) .trigger(GUICombo.EVENT_READY, { instance: this }); }; GUICombo.prototype.update = function update() { var $selected = this.$select.find('option:selected'); if ($selected.prop('disabled')) { this.$element .addClass(GUICombo.JS_CLASS__PLACEHOLDER) .addClass(this.__SETTINGS.classPlaceholder); }else{ this.$element .removeClass(GUICombo.JS_CLASS__PLACEHOLDER) .removeClass(this.__SETTINGS.classPlaceholder); } this._updateView($selected.text()); return this; }; GUICombo.prototype._updateView = function _updateView(value) { var title = ''; this.$value.html(value); this.$element .removeClass(GUICombo.JS_CLASS__OVERFLOW) .removeClass(this.__SETTINGS.classOverflow); if (this.$value.outerWidth(true) - this.$view.outerWidth(true) > this.__SETTINGS.overflowOffset) { this.$element .addClass(GUICombo.JS_CLASS__OVERFLOW) .addClass(this.__SETTINGS.classOverflow); title = value; } this.$select.prop('title', title); }; GUICombo.prototype.disable = function disable(isDisabled) { isDisabled = !!isDisabled; this.$select.prop('disabled', isDisabled); if (isDisabled) { this.$element .addClass(GUICombo.JS_CLASS__DISABLED) .addClass(this.__SETTINGS.classDisabled); } else { this.$element .removeClass(GUICombo.JS_CLASS__DISABLED) .removeClass(this.__SETTINGS.classDisabled); } return this; }; global.GUICombo = GUICombo; }(this); //-- } /gui combo.